<?php
/*******************************************************************************

    FinalsClub.org is a platform for students and faculty to collaborate
    and share their knowledge with the world.

    Copyright (C) 2009  Andrew Magliozzi
 
    This file is a part of FinalsClub.org.

    FinalsClub.org is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
    To contact FinalsClub.org, send an email to info@finalsclub.org, or
    send mail to Finals Club, c/o Veritas Tutors, 1132 Massachusetts Avenue,
    Cambridge, MA 02138.

*******************************************************************************/

/**
 * Summary form.
 *
 * @package    FinalsClub
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class SummaryForm extends BaseSummaryForm
{
	
	
  public function configure()
  {
  	// get all books if this summary type is of book
  	
		if($this->getOption('group_id'))
		{
			$this->widgetSchema['group_id'] = new sfWidgetFormInputHidden();
			$this->validatorSchema['group_id'] = new sfValidatorPass();
			$this->setDefault('group_id', $this->getOption('group_id'));
			
			//only allow user to create a summary for the courses of the group
			$group_courses = GroupCoursePeer::retrieveByGroupId($this->getOption('group_id'));
			
			$course_choices = array();
			foreach($group_courses as $group_course) {
				$course = CoursePeer::retrieveById($group_course->getCourseId());
				$course_choices[$course->getId()] = $course->getSubject().' '.$course->getSection() .' : '.$course->getName();
			}		
			$this->widgetSchema['course_id'] = new sfWidgetFormSelect(
			array('choices' => $course_choices)
			);
			$this->validatorSchema['course_id'] = new sfValidatorPass();
			
			
		}
		else
		{
			
			//if there is no group the get all courses
			$courses = CoursePeer::doSelect(new Criteria());
			
			$course_choices = array();
			foreach($courses as $course) {
				$course_choices[$course->getId()] = $course->getSubject().' '.$course->getSection() .' : '.$course->getName();
			}		
			$this->widgetSchema['course_id'] = new sfWidgetFormSelect(
			array('choices' => $course_choices)
			);
			$this->validatorSchema['course_id'] = new sfValidatorPass();
		
			
		}
		
		//category cohices
		
		$category_choices = array();
		$categories = LibraryPeer::getCategories();
		foreach($categories as $plural=>$singular) {
			$category_choices[$singular] = ucwords($plural);
		}		
		$this->widgetSchema['category'] = new sfWidgetFormSelect(
		array('choices' => $category_choices)
		);
		$this->validatorSchema['category'] = new sfValidatorPass();
		
		
		/*Type is not used yet but it might be used to link summaries to other content on the site
		 * 
		$this->widgetSchema['type'] = new sfWidgetFormInputHidden();
		$this->validatorSchema['type'] = new sfValidatorPass();
		$this->setDefault('type', $this->getOption('type'));
		*/
  	
  }
}
